import { defineConfig, loadEnv } from "vite";
import viteBaseConfig from "./vite.base.config";
import viteDevConfig from "./vite.dev.config";
import viteProdConfig from "./vite.prod.config";

// 策略模式
const envResolver = {
  build: () => {
    // console.log("生产环境");
    return { ...viteBaseConfig, ...viteProdConfig };
  },
  serve: () => {
    // console.log("开发环境");
    return Object.assign({}, viteBaseConfig, viteDevConfig);
  },
};

export default defineConfig(({ command, mode }) => {
  // console.log(command);
  // build还是serve取决于我们敲得命令是开启开发环境还是生产环境
  // process.cwd()
  // console.log("process", process.env);
  const env = loadEnv(mode, process.cwd(), "");
  // console.log("env:", env);
  return envResolver[command]();
});
